<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="租客姓名">
        <el-input v-model="formInline.tenantName" placeholder="请输入租客姓名"></el-input>
      </el-form-item>

      <el-form-item label="房源类型">
        <el-select v-model="formInline.signType" placeholder="请选择">
          <el-option label="请选择" value=""></el-option>
          <el-option label="合租(分散式)" value="1"></el-option>
          <el-option label="整租(分散式)" value="2"></el-option>
          <el-option label="公寓(集中式)" value="3"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="手机号码">
        <el-input v-model="formInline.tenantPhone" placeholder="请输入手机号码"></el-input>
      </el-form-item>

      <el-form-item label="小区名称">
        <el-input v-model="formInline.premiseName" placeholder="请输入小区名称"></el-input>
      </el-form-item>

      <el-form-item label="起租日期">
        <el-input type="date" v-model="formInline.startDate" placeholder="请输入日期"></el-input>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="qingkong">清空</el-button>
      </el-form-item>
    </el-form>

    <template>
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          prop="tenantName"
          label="租客姓名">
        </el-table-column>
        <el-table-column
          prop="cfContractNo"
          label="租房合同编号"
          width="180">
        </el-table-column>
        <el-table-column
          prop="tenantPhone"
          label="电话">
        </el-table-column>
        <el-table-column
          prop="roomName"
          label="房源信息">
        </el-table-column>
        <el-table-column
          prop="signType"
          label="房源类型">
          <template scope="scope">
            <div v-if="scope.row.depositType==1">合租(分散式)</div>
            <div v-if="scope.row.depositType==2">整租(分散式)</div>
            <div v-if="scope.row.depositType==2">公寓(集中式)</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="startDate"
          label="起租日期">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="endDate"
          label="结束日期">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="depositType"
          label="押金方式">
          <template scope="scope">
            <div v-if="scope.row.depositType==1">押一付一</div>
            <div v-if="scope.row.depositType==2">押一付三</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="deposit"
          label="押金">
        </el-table-column>
        <el-table-column
          prop="monthRent"
          label="租金">
        </el-table-column>
        <el-table-column
          prop="contractState"
          label="状态">
          <template scope="scope">
            <div v-if="scope.row.contractState==2" style="color: red">已提交</div>
            <div v-if="scope.row.contractState==3" style="color: red">已解约</div>
            <div v-if="scope.row.contractState==4" style="color: red">已结束</div>
            <div v-if="scope.row.contractState==9" style="color: red">作废</div>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="formInline.pageNum"
          :page-sizes="[10, 20, 30]"
          :page-size="formInline.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </template>
  </div>
</template>

<script>
  import { houses } from "@/api/system/tenant";

  export default {
    name: "index",
    data(){
      return{
        tableData:[],
        formInline:{
          pageNum:1,
          pageSize:10,
          tenantName:'',
          signType:'',
          tenantPhone:'',
          premiseName:'',
          startDate:'',
        },
        total:0,
      }
    },
    methods:{
      list(){
        houses(this.formInline).then(res=>{
          console.log(res);
          this.tableData=res.list;
          this.total=res.total;
        })
      },
      onSubmit(){
        this.list();
      },
      qingkong(){
        this.formInline={};
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.formInline.pageSize=val;
        this.list();
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.formInline.pageNum=val;
        this.list();
      }
    },
    created() {
      this.list();
    }
  }
</script>

<style scoped>

</style>
